package com.bdqn.staffmanagementsystem.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Configuration
public class MyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object loginUser = request.getSession().getAttribute("LoginUser");
        System.out.println(loginUser);
        if (loginUser!=null){
            return true;
        }else {
            request.setAttribute("LoginPrompt","还未登录请先登录");
            request.getRequestDispatcher("/toIndex").forward(request,response);
            return false;
        }
    }
}
